const { DataTypes } = require('sequelize');
const sequelize = require('../database');
const Course = require('./Course');
const User = require('./User');

const Payment = sequelize.define('Payment', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },
  amount: {
    type: DataTypes.FLOAT,
    allowNull: false,
  },
  status: {
    type: DataTypes.ENUM('created', 'paid', 'failed'),
    allowNull: false,
    defaultValue: 'created',
  },
  appid: {
    type: DataTypes.STRING,
    allowNull: true,
  },
  mch_id: {
    type: DataTypes.STRING,
    allowNull: true,
  },
  nonce_str: {
    type: DataTypes.STRING,
    allowNull: true,
  },
  sign: {
    type: DataTypes.STRING,
    allowNull: true,
  },
  body: {
    type: DataTypes.STRING,
    allowNull: true,
  },
  out_trade_no: {
    type: DataTypes.STRING,
    allowNull: true,
  },
  total_fee: {
    type: DataTypes.STRING,
    allowNull: true,
  },
  spbill_create_ip: {
    type: DataTypes.STRING,
    allowNull: true,
  },
  notify_url: {
    type: DataTypes.STRING,
    allowNull: true,
  },
  trade_type: {
    type: DataTypes.STRING,
    allowNull: true,
  },
});

Payment.belongsTo(Course, { foreignKey: 'courseId' });
Payment.belongsTo(User, { foreignKey: 'userId' });

module.exports = Payment;
